﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TB_CS.Price_Noti
{
    public partial class Link_WH : Form
    {
        public Link_WH()
        {
            InitializeComponent();
        }

        private void Link_WH_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Clear();
            DataSet Link_Type_DST = Class.SysInfo.WSPP.Get_Link_Type();
            for(int i=0;i<Link_Type_DST.Tables[0].Rows.Count;i++)
            {
                comboBox1.Items.Add(Link_Type_DST.Tables[0].Rows[i][1].ToString());
            }

            dataGridView2.DataSource = Class.SysInfo.WSPP.Get_Link().Tables[0];
            dataGridView1.DataSource = Class.SysInfo.WSPP.Get_PP_Follow_List(
                Class.SysInfo.GET_Seller_Nick().ToString()).Tables[0];
        }

        private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int Link_ID =Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString());
            Class.SysInfo.WSPP.ADD_PP_FOLLOW(Link_ID, Convert.ToInt32(Class.SysInfo.INFO_Seller_ID));

            dataGridView2.DataSource = Class.SysInfo.WSPP.Get_Link().Tables[0];
            dataGridView1.DataSource = Class.SysInfo.WSPP.Get_PP_Follow_List(
                Class.SysInfo.GET_Seller_Nick().ToString()).Tables[0];
        }

        private void textBox1_DoubleClick(object sender, EventArgs e)
        {
            textBox4.Text = textBox1.Text.Trim().ToString().Split('=')[1].ToString();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text=="")
            {
                MessageBox.Show("请输入URL");
            }
            else if(comboBox1.Text=="")
            {
                MessageBox.Show("请选择订单类型");
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("请输入标题");
            }
            else if (textBox3.Text == "")
            {
                MessageBox.Show("请输入该链接的卖家ID");
            }
            else if (textBox4.Text == "")
            {
                MessageBox.Show("请输入商品ID，或者双击地址栏即可自动获取");
            }
            else
            {
                //开始处理
                Class.SysInfo.WSPP.INSERT_LINK(textBox1.Text.Trim().ToString(),
                    textBox4.Text.Trim().ToString(), textBox2.Text.Trim().ToString(),
                    textBox3.Text.Trim().ToString(), comboBox1.Text.Trim().ToString());
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";

                dataGridView2.DataSource = Class.SysInfo.WSPP.Get_Link().Tables[0];
                dataGridView1.DataSource = Class.SysInfo.WSPP.Get_PP_Follow_List(
                    Class.SysInfo.GET_Seller_Nick().ToString()).Tables[0];
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Class.SysInfo.WSPP.UN_FOLLOW_PP_LINK(Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()),
               Convert.ToInt32(Class.SysInfo.INFO_Seller_ID));
            dataGridView2.DataSource = Class.SysInfo.WSPP.Get_Link().Tables[0];
            dataGridView1.DataSource = Class.SysInfo.WSPP.Get_PP_Follow_List(
                Class.SysInfo.GET_Seller_Nick().ToString()).Tables[0];
        }
    }
}
